package icu.sunway.gushenBlogBackEnd.Controller;

import icu.sunway.gushenBlogBackEnd.Entity.Data.LikeDO;
import icu.sunway.gushenBlogBackEnd.Entity.View.ResultVO;
import icu.sunway.gushenBlogBackEnd.Service.LikeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/like")
public class LikeController {
    final LikeService likeService;

    LikeController(LikeService likeService) {
        this.likeService = likeService;
    }

    @PostMapping("/add")
    ResultVO<Boolean> addLike(@RequestParam String article_id,
                              @RequestHeader String token) {
        return likeService.addLike(article_id, token);
    }

    @DeleteMapping("/remove")
    ResultVO<Boolean> removeLike(@RequestParam String id) {
        return likeService.removeLike(id);
    }

    @GetMapping("/list")
    ResultVO<List<LikeDO>> getLikeList() {
        return likeService.getLikeList();
    }

    @GetMapping("/count_from_article")
    ResultVO<Long> getLikeCountFromArticle(@RequestParam String article_id) {
        return likeService.getLikeCountFromArticle(article_id);
    }

    @GetMapping("/check")
    ResultVO<Boolean> checkLike(@RequestParam String article_id,
                                @RequestHeader String token) {
        return likeService.checkIsLiked(article_id, token);
    }

    @DeleteMapping("/remove_from_article")
    ResultVO<Boolean> removeLikeFromArticle(@RequestParam String article_id,
                                            @RequestHeader String token) {
        return likeService.removeLikeFromArticle(article_id, token);
    }

    @GetMapping("/list_by_user")
    ResultVO<List<LikeDO>> getLikeListByUser(@RequestHeader String token) {
        return likeService.getLikeListByUser(token);
    }

    @GetMapping("/count_from_user")
    ResultVO<Long> getLikeCountFromUser(@RequestHeader String token) {
        return likeService.getLikeCountFromUser(token);
    }

    @GetMapping("/list_by_user_by_page")
    ResultVO<List<LikeDO>> getLikeListByUserByPage(@RequestHeader String token,
                                                   @RequestParam int curPage,
                                                   @RequestParam int pageSize) {
        return likeService.getLikeListByUserByPage(token, curPage, pageSize);
    }
}
